<section class="content-header">
    <h1>
        订单管理
        <small></small>
    </h1>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- general form elements -->
            <div class="box box-default">
                <div class="box-header with-border">
                    <h3 class="box-title">订单搜索</h3>
                </div>
                <!-- form start -->
                <form class="form-horizontal" action="{:U('Admin/Order/search')}" method="post">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">订单ID</label>

                            <div class="col-sm-3">
                                <input class="form-control" name="id" placeholder="" value="{$orderPost.id}"
                                       type="text">
                            </div>

                            <label class="col-sm-1 control-label">订单编号</label>

                            <div class="col-sm-3">
                                <input class="form-control" name="orderid" placeholder="" value="{$orderPost.orderid}"
                                       type="text">
                            </div>

                            <label class="col-sm-1 control-label">用户ID</label>

                            <div class="col-sm-3">
                                <input class="form-control" name="user_id" placeholder="" value="{$orderPost.user_id}"
                                       type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-1 control-label">支付方式</label>

                            <div class="col-sm-3">
                                <select name="payment" class="form-control">
                                    <option value="-10">不选择支付方式</option>
                                    <option value="0">账户支付</option>
                                    <option value="1">微信支付</option>
                                    <option value="2">支付宝支付</option>
                                    <option value="3">货到付款</option>
                                </select>
                            </div>

                            <label class="col-sm-1 control-label">支付状态</label>

                            <div class="col-sm-3">
                                <select name="pay_status" class="form-control">
                                    <option value="-10">不选择支付状态</option>
                                    <option value="0">未支付</option>
                                    <option value="1">已支付</option>
                                </select>
                            </div>

                            <label class="col-sm-1 control-label">订单状态</label>

                            <div class="col-sm-3">
                                <select name="status" class="form-control">
                                    <option value="-10">不选择订单状态</option>
                                    <option value="0">未处理</option>
                                    <option value="1">已发货</option>
                                    <option value="2">已完成</option>
                                    <option value="-1">已取消</option>
                                    <option value="-2">退货中</option>
                                    <option value="-3">退货完成</option>
                                    <option value="-4">申请退货</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-1 control-label">商品</label>

                            <div class="col-sm-3">
                                <select name="product_id" class="form-control">
                                    <option value="-10">不选择商品</option>
                                    <volist name="productList" id="list">
                                        <option value="{$list.id}">{$list.name}</option>
                                    </volist>
                                </select>
                            </div>

                            <label class="col-sm-1 control-label">时间范围</label>

                            <div class="col-sm-7">
                                <div class="input-group">
                                    <div class="input-group-addon">
                                        <i class="fa fa-clock-o"></i>
                                    </div>
                                    <input type="text" class="form-control pull-right" name="timeRange"
                                           id="reservationtime" value="{$orderPost.timeRange}">
                                </div>
                            </div>
                            <!-- /.input group -->
                        </div>
                    </div>
                    <!-- /.box-body -->

                    <div class="box-footer">
                        <div class="col-sm-2">
                            <button type="submit" class="btn btn-block btn-danger">开始搜索</button>
                        </div>
                    </div>
                </form>
            </div>
            <!-- /.box -->
        </div>
        <!--/.col (right) -->
    </div>

    <div class="row">
        <!-- /.col -->
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-header with-border">
                    <h3 class="box-title">订单管理</h3>
                    <!-- /.box-tools -->
                </div>
                <!-- /.box-header -->
                <div class="box-body no-padding">
                    <div class="mailbox-controls">
                        <div class="btn-group">
                            <a href="{:U('Admin/Order/export',array('status'=>I('get.status') , 'pay_status'=>I('get.pay_status') ,'day'=>I('get.day')))}"
                               target="_blank" class="btn btn-danger">
                                导出全部订单
                            </a>
                        </div>
                        <!-- /.btn-group -->
                    </div>
                    <div class="table-responsive" style="overflow-x: visible;">
                        <table class="table table-hover">
                            <tbody>
                            <tr>
                                <th class="hidden-xs">
                                    <label><input onchange="checkAll()" type="checkbox" value=""></label>
                                </th>
                                <th>ID</th>
                                <th>订单编号</th>
                                <th>联系人</th>
                                <th>价格</th>
                                <th>优惠</th>
                                <th>支付方式</th>
                                <th>支付状态</th>
                                <th>订单状态</th>
                                <th>订单详情</th>
                                <th>备注</th>
                                <th>时间</th>
                            </tr>
                            <volist name="orderList" id="order">
                                <tr>
                                    <td class="hidden-xs">
                                        <label><input name="checkbox" class="check" type="checkbox"
                                                      value="{$order.id}"></label>
                                    </td>
                                    <td>
                                        {$order.id}
                                    </td>
                                    <td>
                                        {$order.orderid}
                                    </td>
                                    <td>
                                        <div class="btn-group" style="margin: 0px;">
                                            <button class="btn btn-default dropdown-toggle"
                                                    data-toggle="dropdown">
                                                {$order.contact.name}<span class="caret"></span></button>
                                            <ul class="dropdown-menu">
                                                <li>
                                                    <a href="#">联系方式：{$order.contact.phone}</a>
                                                </li>
                                                <li>
                                                    <a href="#">联系地址：{$order.contact.province}|{$order.contact.city}|{$order.contact.address}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td class="hidden-xs">
                                        {$order.totalprice}
                                    </td>
                                    <td class="hidden-xs">
                                        {$order.discount}
                                    </td>
                                    <td class="hidden-xs">
                                        <if condition="$order.payment eq 0">账户支付
                                            <elseif condition="$order.payment eq 1"/>
                                            微信支付
                                            <elseif condition="$order.payment eq 2"/>
                                            支付宝支付
                                            <else/>
                                            货到付款
                                        </if>
                                    </td>
                                    <td class="hidden-xs">
                                        <if condition="$order.pay_status eq 1">已支付
                                            <else/>
                                            <font color="red">未支付</font></if>
                                    </td>
                                    <td class="hidden-xs">
                                        <if condition="$order.status eq -1">已取消
                                            <elseif condition="$order.status eq 0"/>
                                            <font color="red">未处理</font>
                                            <elseif condition="$order.status eq 1"/>
                                            <font color="blue">已发货</font>
                                            <elseif condition="$order.status eq -2"/>
                                            <font color="blue">已退货</font>
                                            <else/>
                                            已完成
                                        </if>
                                    </td>
                                    <td class="hidden-xs">
                                        <div class="btn-group" style="margin: 0px;">
                                            <button class="btn btn-default dropdown-toggle"
                                                    data-toggle="dropdown">
                                                订单详情<span class="caret"></span></button>
                                            <ul class="dropdown-menu" style="max-width: none;">
                                                <li><a>
                                                    <table style="text-align: center;">
                                                        <h5>订单商品详情：</h5>
                                                        <tr>
                                                            <td>商品名称|</td>
                                                            <td>商品属性|</td>
                                                            <td>商品价格|</td>
                                                            <td>商品数量</td>
                                                        </tr>
                                                        <php>
                                                            $data = $order[detail];
                                                            for($i=0;$i < count($data);$i++){
                                                            echo '
                                                            <tr>
                                                                <td>'.$data[$i][name].'</td>
                                                                <td>'.$data[$i][attr].'</td>
                                                                <td>'.$data[$i][price].'</td>
                                                                <td>'.$data[$i][num].'</td>
                                                            </tr>
                                                            ';
                                                            }
                                                        </php>
                                                    </table>
                                                </a></li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td class="hidden-xs">
                                        {$order.remark}
                                    </td>
                                    <td class="hidden-xs">
                                        {$order.time}
                                    </td>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                        <div class="box-footer no-padding">
                            <div class="mailbox-controls">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger "
                                            onclick="batchUrl('{:U(\'Admin/Order/update\',array(\'status\'=>1))}')">发货
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger "
                                            onclick="batchUrl('{:U(\'Admin/Order/update\',array(\'pay_status\'=>1))}')">
                                        已支付
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger "
                                            onclick="batchUrl('{:U(\'Admin/Order/update\',array(\'status\'=>-1))}')">取消
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger "
                                            onclick="batchUrl('{:U(\'Admin/Order/update\',array(\'status\'=>2))}')">已完成
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger "
                                            onclick="batchUrl('{:U(\'Admin/Order/update\',array(\'status\'=>-2))}')">已退货
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger "
                                            onclick="batchUrl('{:U(\'Admin/Order/export\',array(\'status\'=>I(\'get.status\') , \'pay_status\'=>I(\'get.pay_status\') ,\'day\'=>I(\'get.day\')))}',false)">
                                        导出订单
                                    </button>
                                </div>
                                <!-- /.btn-group -->
                                <div class="pull-right">
                                    {$page}
                                    <!-- /.btn-group -->
                                </div>
                                <!-- /.pull-right -->
                            </div>
                        </div>
                    </div>
                    <!-- /.mail-box-messages -->
                </div>
            </div>
            <!-- /. box -->
        </div>
        <!-- /.col -->
    </div>
</section>
<script type="text/javascript">
    $(function () {
        $('#reservationtime').daterangepicker({
            timePicker: true,
            timePickerIncrement: 30,
            format: 'YYYY-MM-DD h:mm:ss',
            separator: ' --- ',
        });
        if ('{$orderPost}') {
            $('select[name="payment"]').val('{$orderPost.payment}');
            $('select[name="pay_status"]').val('{$orderPost.pay_status}');
            $('select[name="status"]').val('{$orderPost.status}');
            $('select[name="product_id"]').val('{$orderPost.product_id}');
        }
    });
</script>